// pages/my/addClass/addClass.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindInputTeacherPhone:function(res){
    var that = this
    that.setData({
      teacherPhone:res.detail.value
    })
  },
  addclass:function(){
    var that = this
    wx.getStorage({
      key: 'student_id',
      success: function (resl) {
        wx.request({
          url: base_url+'/addClasses/',
          method: 'POST',
          data: {
            student_id: resl.data,
            teacherPhone: that.data.teacherPhone
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if(res.data['flag'] == true){
              wx.setStorage({
                key: 'schoolName',
                data: res.data['schoolName'],
                success: function () {
                }
              })
              wx.setStorage({
                key: 'teacherID',
                data: res.data['teacherID'],
                success: function () {
                }
              })
              wx.setStorage({
                key: 'teacherName',
                data: res.data['teacherName'],
                success: function () {
                }
              })
              wx.navigateTo({
                url: '../selectClass/selectClass',
                success: function (res) {
                  
                },
                fail: function () {

                }
              })
            }else{
              wx.showModal({
                title: '提示',
                content: '该教师不存在',
                showCancel: false,
                confirmText: '确定',
                success: function (res) {
                }
              })
            }
          }
        })
      },
      fail: function (res) {

      }
    })
  }
})